// import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
import { systemid, productid } from '../../atom/config';
import doc_code from '@dfeidao/atom-nodejs/msg/doc-code';
import operate from '@dfeidao/atom-nodejs/db/operate';

interface Message {

	data: {
		event_no: string;
		event_location: string;
		event_record: string;
		process_result: string;
		cause_analysis: string;
		precaution: string;
		principal_opinion: string;
		memo: string;
		event_theme: string;
		resume_attachment: string;
		principal_part: string;
		management_office: string;
		event_time: string;

	}

}
// 表名	burst_event				
// 标题	突发事件				
// 字段名称	字段标题	字段类型	字段长度	是否为空	是否主键
// _id	id	string	50	ⅹ	√
// productid	产品ID	string	50	√	ⅹ
// event_no	事件编号	string	32	√	ⅹ
// event_theme	事件主题	string	32	√	ⅹ
// management_office	管理处	string	64	√	ⅹ
// principal_part	负责部门	string	32	√	ⅹ
// event_time	事发时间	timestamp	50	√	ⅹ
// event_location	事发地点	string	64	√	ⅹ
// event_record	事件记录	string	128	√	ⅹ
// process_result	处理结果	string	128	√	ⅹ
// cause_analysis	原因分析	string	128	√	ⅹ
// precaution	预防措施	string	128	√	ⅹ
// principal_opinion	负责人意见	string	128	√	ⅹ
// report_time	报告时间	timestamp	50	√	ⅹ
// reporter_no	报告人编号	string	32	√	ⅹ
// reporter_name	报告人姓名	string	32	√	ⅹ
// resume_attachment	附件	document	50	√	ⅹ
// memo	备注	string	500	√	ⅹ
// annex_name	附件名称	string	50	√	ⅹ
// management_office_no	管理处编号	string	32	√	ⅹ
// principal_part_no	负责部门编号	string	32	√	ⅹ


export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders) {
	// log('Service begin path:e:\7.29考核\kh\src\LiQiuLiang\zj-000004\s001,action_id:' + action_id);

	const res = await doc_code(action_id, session_id, systemid, 'BM0014048', '', 1);

	const { exec, insert } = operate(action_id, session_id, systemid);

	insert('burst_event', {
		event_no: res.result,

		event_theme: message.data.event_theme,
		event_location: message.data.event_location,
		event_record: message.data.event_record,
		process_result: message.data.process_result,
		cause_analysis: message.data.cause_analysis,
		precaution: message.data.precaution,
		principal_opinion: message.data.principal_opinion,
		memo: message.data.memo,
		resume_attachment: message.data.resume_attachment,
		principal_part: message.data.principal_part,
		management_office: message.data.management_office,
		event_time: message.data.event_time,
		reporter_name: '张三',
		report_time: message.data.event_time,

		productid
	})
	const r = await exec();

	// log('Service end path:e:\7.29考核\kh\src\LiQiuLiang\zj-000004\s001,action_id:' + action_id);
	return r
}
